package cn.hiapi.shopkeeper.service.shopkeeper;

import cn.hiapi.basic.exception.BasicException;
import cn.hiapi.interfaces.shop.shop.IShopVerifyPermissionService;
import cn.hiapi.shopkeeper.consts.AppConst;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author AdinZ
 * @date 2023/2/10 14:48
 */
@Service
public class ShopPermissionService implements IShopVerifyPermissionService {
    private Map<String, List<Long>> permission = new HashMap<>();

    public ShopPermissionService() {
        permission.put(AppConst.SHOP_ROLE_AMOUNT, Arrays.asList(0L));
        permission.put(AppConst.SHOP_ROLE_EDIT_INFO, Arrays.asList(0L));
        permission.put(AppConst.SHOP_ROLE_ACCOUNT, Arrays.asList(0L));
        permission.put(AppConst.SHOP_ROLE_EDIT_INFO, Arrays.asList(0L));
        permission.put(AppConst.SHOP_ROLE_EDIT_USER, Arrays.asList(0L, 1L));
    }

    @Override
    public void permission(long shopId, long rid, String role) {
        if (rid == 0) return;
         if (!permission.containsKey(role)) throw new BasicException("没有这个权限");
        List<Long> longs = permission.get(role);
        if (longs == null || longs.isEmpty()) throw new BasicException("权限错误");
        if (!longs.contains(rid)) throw new BasicException("没有操作权限");
    }
}
